$(function () {
  loginVerify();
});

function loginVerify() {
  layui.use('layer', function () { //独立版的layer无需执行这一句
    var $ = layui.jquery, layer = layui.layer; //独立版的layer无需执行这一句
    $.ajax({
      type: "post",
      url: "/mainMenu/loginVerify",
      success: function (data) {
        if (data == "yes") {
          console.log("用户已登陆！");
          //根据session中的user对象初始化：这里后续还要补充几个函数

          
        } else {
          console.log("用户未登录，请先登录！");
          //弹出登陆框
          //示范一个公告层
          layer.open({
            type: 1
            ,title: ['请先进行登录', 'font-size:16px;font-weight:bold'] //不显示标题栏
            ,closeBtn: false
            ,area: '300px;'
            ,shade: 0.8
            ,id: 'LAY_layuipro' //设定一个id，防止重复弹出
            ,btnAlign: 'c'
            ,moveType: 1 //拖拽模式，0或者1
            ,content: $('#mobile-login-div')
          });
        }
      }
    });
  });

}

function mobile_login() {
  var layer = layui.layer;
  var user_number = $('input[name="user_number"]').val();
  var password = $('input[name="password"]').val();
  console.log("MSG from mobile login: account:" + user_number + "," + "password:"
      + password);
  if (user_number == "" || password == "") {
    layui.use('layer', function () {
      layer.msg("账号或者密码为空", {time: 500, anim: -1, offset: '80%'});
    });
  } else {
    $.ajax({
      type: "POST",//方法类型
      url: "/mobile/login_mobile",//url
      data: {
        user_number: user_number,//这边要和数据表对应的实体类属性一致
        password: password
      },
      dataType:"text",
      success: function (result) {
        console.log("---------------");
        console.log("|"+result+"|"); //发现打印出的字符串是
        if(result=="success"){
          window.location.href = 'mobile/gotoMainPage_v2';
        }else{
          alert("账号或者密码错误！");
        }
      },
      error: function () {
        layui.use('layer', function () {
          layer.msg("未知错误！", {time: 1000, anim: -1, offset: '80%'});
        });
      }
    });
  }

}